import Vue from 'vue'
import VueRouter from 'vue-router'
import index from '@/views/index/index.vue'
import ferio from '@/views/ferio/ferio'
import heiuo from '@/views/heiuo/heiuo'
import lisxz from '@/views/lisxz/lisxz'
import log from '@/views/log/log'
import meixs from '@/views/meixs/meixs'
import wsxdz from '@/views/wsxdz/wsxdz'
import index1 from '@/views/index/index1'
import fenglei from '@/views/index/fenglei'
import gowu from '@/views/index/gowu'
import wod from '@/views/index/wod'
import store from '@/store'

Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  routes: [
    {
      path: '/',
      component: index,
      children: [
        { path: '/', component: index1 },
        { path: 'gowu', component: gowu },
        { path: 'fenglei', component: fenglei },
        { path: 'wod', component: wod }
      ]
    },
    { path: '/ferio', component: ferio },
    { path: '/heiuo', component: heiuo },
    { path: '/lisxz', component: lisxz },
    { path: '/log', component: log },
    { path: '/meixs', component: meixs },
    { path: '/wsxdz/:id', component: wsxdz }
  ],
  base: process.env.BASE_URL
})
export default router

const Mypath = ['/wod', '/heiuo', '/lisxz']

router.beforeEach((to, from, next) => {
  if (!Mypath.includes(to.path)) {
    next()
    return false
  }
  const token = store.state.urel.userinfo.token
  if (token) {
    next()
  } else {
    next('/log')
  }
})
